package com.lc.sell.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * 生成一串随机数
 */
public class IdGenerator {

    private static SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");


    public static String UidGenerator(){
        Random random=new Random();
        Integer number=random.nextInt(1000000)+100000;

        return String.valueOf(number);
    }

    public static String QchGenerator(){
        Random random=new Random();
        Integer number=random.nextInt(100)+18;
        Integer number1=random.nextInt(1000)+1000;
        return number1+""+number;
    }

    /**
     * 生成唯一的主键
     * 格式：时间+随机数
     * @return
     */
    public static synchronized String genUniqueKey(){
        Random random=new Random();
        Integer number=random.nextInt(90)+1000;

        return System.currentTimeMillis()+String.valueOf(number);
    }

    public static void main(String[] args) {
        String  ceil = IdGenerator.UidGenerator();
        String s = IdGenerator.QchGenerator();

        System.out.println(ceil);
        System.out.println(s);
    }


    /**
     * 生成随机ID（23）
     * @return
     */
    public static String getDateTimeAndRandomForID(){
        int random = (int)((Math.random()*9+1)*100000);
        String id = format.format(new Date())+random;
        return id;
    }


}
